package org.example.controller;


import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.example.BlogServiceApi;
import org.example.pojo.AddBlogInfoRequest;
import org.example.pojo.BlogInfoResponse;
import org.example.pojo.Result;
import org.example.pojo.UpBlogRequest;
import org.example.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RequestMapping("/blog")
@RestController
public class BlogController implements BlogServiceApi {
    @Autowired
    private BlogService blogService;
    @Override
    public Result<List<BlogInfoResponse>> getList() {
        return Result.success(blogService.getList());
    }

    @Override
    public Result<BlogInfoResponse> getBlogDeatail(@NotNull Integer blogId) {
        log.info("getBlogDetail, blogId: {}", blogId);
        return Result.success(blogService.getBlogDeatil(blogId));
    }

    @Override
    public Result<Boolean> addBlog(@Validated  @RequestBody AddBlogInfoRequest addBlogInfoRequest) {
        log.info("addBlog, 接收到参数: {}", addBlogInfoRequest);
        return Result.success(blogService.addBlog(addBlogInfoRequest));
    }

    @Override
    public Result<Boolean> updateBlog(@Valid @RequestBody UpBlogRequest upBlogRequest) {
        log.info("updateBlog, 接收到参数: {}", upBlogRequest);
       return Result.success( blogService.update(upBlogRequest));
    }

    @Override
    public Result<Boolean> deleteBlog(@NotNull Integer blogId) {
        log.info("deleteBlog, 接收到参数: {}", blogId);
       return Result.success(blogService.delete(blogId));
    }
}
